/**
 * Author: Shen Yanqiu
 * Date: 2017-12-19
 * Time: 18:12
 *
 */
import React from 'react';
import { routerRedux } from 'dva/router';
import PropTypes from 'prop-types';
import { connect } from 'dva';
import { Page } from 'components';
import queryString from "query-string";
import { List, Operation, Action } from './Components';
import TopRightButton from './../../components/TopOperation/TopRightButton';
import {message} from "antd/lib/index";
import { routerTool } from 'utils';

class SatisfactionSurvey extends React.Component {
  static propTypes = {
    loading: PropTypes.object,
    dispatch: PropTypes.func,
    satisfactionsurvey: PropTypes.object,
    location: PropTypes.object,
  };

  state = {
    deleteArray: [],
  }
  getCheckbox = (data) => {
    console.log(data);
    this.setState({
      deleteArray: data,
    });
  };
  render () {
    const { loading, location, satisfactionsurvey, dispatch } = this.props;
    location.query = queryString.parse(location.search);
    const { list, pagination } = satisfactionsurvey;
    const listProps = {
      dataSource: list,
      loading: loading.effects['satisfactionsurvey/getExpenditureList'],
      pagination,

      onChange (_pagination) {
        const { query, pathname } = location;
        dispatch({
          type: 'satisfactionsurvey/getExpenditureList',
          payload: {
            ...query,
            current: _pagination.current,
            pageSize: _pagination.pageSize,
          },
        });
      },

      onSeeItem (record) {
        dispatch({
          type: 'satisfactionsurvey/onSeeItemModal',
          payload: {
            id: record.id,
          },
        });
      },

      onDeleteItem (id, record) {
        dispatch({
          type: 'satisfactionsurvey/onDeleteItemModal',
          payload: {
            id: id,
          },
        });
      },

    };
    function SearchData (data) {
      dispatch({
        type: 'satisfactionsurvey/searchData',
        payload: {
          formData: data,
        },
      });
    }
    const clickHandle = () => {
      dispatch(routerTool.redirectTo({
        name: 'AddSatisfactionSurvey',
      }));
    }
    // 批量删除
    const remove = () => {
      if (this.state.deleteArray.length === 0) {
        message.error("请先选择需要删除的信息");
        return;
      }
      dispatch({
        type: 'satisfactionsurvey/onDeleteItemModal',
        payload: {
          params: {
            ids: this.state.deleteArray,
          },
        }
      });
    }
    return (
      <Page loading={loading.models.expenditure}>
        <Operation SearchData={SearchData} remove={remove} />
        {/*<Action onCreateClick={clickHandle} />*/}
        <List {...listProps} getCheckbox={this.getCheckbox} />

        {/*<TopRightButton contentText="发起调查" clickHandle={clickHandle} />*/}
      </Page>
    );
  }
}
export default connect(({ loading, satisfactionsurvey }) => ({ loading, satisfactionsurvey }))(SatisfactionSurvey);
